package com.webSite.demo.cy.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.webSite.demo.cy.bean.HomeNews;

@Mapper
public interface HomeNewsMapper {

	@Select(value="select * from home_news where state=1")
	List<HomeNews> findAllInfo();
	
	@Select(value="select * from home_news where state=1 limit #{arg0},5")
	List<HomeNews> findAllPage(int index);
	
	@Select(value="select * from home_news  where state=1 and id!= #{id} ORDER BY  RAND() LIMIT #{num}")
	List<HomeNews> findRandNews(@Param("id")int id,@Param("num")int num);
	
	@Select(value="select * from home_news where id=#{id}")
	HomeNews findOne(@Param("id")int id);
	
	@Insert(value="insert into home_news(title, content, state, created, updated,image) value(#{title},#{content},#{state},#{created},#{updated},#{image})")
	int insertHomeNews(HomeNews homeNews);
	
	@Update(value="update home_news set title=#{title} ,content=#{content},updated=#{updated},image=#{image} where id=#{id}")
	int updateHomeNews(HomeNews homeNews);
	
	@Update(value="update home_news set state=0 where id=#{0}")
	int updateState(int id);
}
